<template>
  <div>
    <a-modal
      title="编辑"
      :visible="openDialog"
      :confirm-loading="confirmLoading"
      @ok.prevent="handleOk"
      @cancel="handleCancel"
    >
      <div>
        <a-form-model
          :model="editform"
          :rules="editformRules"
          ref="editform"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          @afterClose="mainDialogClose"
        >
          <a-form-model-item label="程序名:" prop="newProduceName">
            <a-input v-model="editform.newProduceName" />
          </a-form-model-item>
        </a-form-model>
      </div>
    </a-modal>
  </div>
</template>
<script>
import api from '@/api/equipment';

export default {
  props: {
    openDialog: Boolean,
    formData: Object,
  },
  data() {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      visible: false,
      confirmLoading: false,
      editform: {
        newProduceName: '',
      },
      idList: [],
      editformRules: {
        newProduceName: [{ required: true, message: '内容不能为空', trigger: 'change' }],
      },
    };
  },

  methods: {
   
    handleOk() {
      var _that = this;
      this.$refs.editform.validate(async (valid) => {
        // 校验未全部通过，结束当前提交
        if (!valid) {
          return false;
        } else {
          let idList = [];
          idList.push(this.formData.opId);
          const res = await api.postamendroutinename({
            idList,
            newProduceName: this.editform.newProduceName,
          });
          if (res.msgCode == 0) {
            _that.$message.success({
              content: res.msgDesc,
            });

            _that.$emit('update:openDialog', false);
          } else {
            _that.$message.error();
            ({
              content: res.msgDesc,
            });
            _that.$emit('update:openDialog', false);
          }
        }
        _that.mainDialogClose();
      });
    },
    handleCancel(e) {
      this.$emit('update:openDialog', false);
    },
    mainDialogClose() {
      this.$emit('closeDialogRefreshData');
    },
  },
};
</script>
<style scoped>
</style>